﻿@model IEnumerable<FaWorks.WebSite.Models.Knowledge.KnowledgeType>

<div class="container bs-docs-container">
    <div class="row">
        @foreach (var item in Model)
        {
            <div class="col-md-3">
                <div class="metro">
                    <a href="/Knowledge/@item.Name/">@item.Name</a>
                </div>
            </div>
        }
        <div id="addTypeContainer" class="col-md-3 hidden">
            <div class="metro">
                <a>+</a>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">知识库分类明细</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="iptName" class="col-md-2 control-label">名称</label>
                        <div class="col-md-10">
                            <input id="hidID" type="hidden" class="form-control" />
                            <input id="iptName" type="text" class="form-control" placeholder="Name" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" onclick="save()">Save changes</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

@section Styles {
    <style type="text/css">
        .metro {
            text-align: center;
            border: 1px dashed #ccc;
            margin: 30px 10px 0 10px;
        }

            .metro:hover {
                border-bottom: 1px solid #0094ff;
            }
    </style>
}

@section Scripts {
    <script type="text/javascript">
        function showEdit(model) {
            if (model) {
                $('#hidID').val(model.id);
                $('#iptName').val(model.Name);
            } else {
                $('#hidID').val('');
                $('#iptName').val('');
            }

            $('#myModal').modal('show');
        }

        function save() {
            var id = $('#hidID').val();
            var model = {
                Name: $('#iptName').val()
            };

            $.ajax({
                url: '/Model/KnowledgeType' + (id ? '?id=' + id : ''),
                type: (id ? 'PUT' : 'POST'),
                data: model,
                async: false
            }).then(function (result) {
                if (result.Success) {
                    $('#myModal').modal('hide');
                    location.href = location.href;
                }
            });
        }

        $(function () {
            if (userJson.UserName == 'ligd' ||
                userJson.UserName == 'liuy03') {
                $('#addTypeContainer')
                    .removeClass('hidden')
                    .on('click', showEdit);
            };
        });
    </script>
}